package cn.tedu.sp09.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp09.fenign.ItemClient;
import cn.tedu.sp09.fenign.OrderClient;
import cn.tedu.sp09.fenign.UserClient;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.List;

@RestController
@Slf4j
public class FeignController {
@Autowired
private ItemClient  itemClient;

@Autowired
private UserClient userClient;
@Autowired
    private OrderClient  orderClient;
@GetMapping("/item-service/{orderId}")
public JsonResult<List<Item>> getItems(@PathVariable String orderId){
    return itemClient.getItem(orderId);
}
@PostMapping("/item-service/decreaseNumber")
public JsonResult<List<Item>> decreaseNumber(@RequestBody List<Item> items){
    return itemClient.decreaseNumber(items);
}
@GetMapping("/user-service/{userId}")
public JsonResult<User> getUser(@PathVariable Integer userId){
    return userClient.getUser(userId);
}
@GetMapping("/user-service/{userId/score}")
public JsonResult<User> addScore(@PathVariable Integer userId,Integer score){
    return userClient.addScore(userId, score);
}
@GetMapping("/order-service/{orderId}")
public JsonResult<Order> getorder(@PathVariable String orderId){
    return orderClient.getOrder(orderId);
}
@GetMapping("/order-service")
public JsonResult<Order> getItems(){
    return orderClient.addOrdr();
}

}
